var t = getApp(), a = void 0;

Page({
    data: {
        order: {},
        eva: {},
        score: 0,
        text: "",
        textarea: ""
    },
    textareaInput: function(t) {
        this.setData({
            textarea: t.detail.value
        });
    },
    clickStar: function(t) {
        var e = t.currentTarget.dataset.index + 1, d = "";
        d = 1 == e ? "非常不满意，各方面都很差" : 2 == e ? "不满意，比较差" : 3 == e ? "一般，需要改善" : 4 == e ? "比较满意，但仍可改善" : "非常满意无可挑剔", 
        a.setData({
            score: e,
            text: d
        });
    },
    getEva: function(e) {
        t.com.post("wx/evaluate/find", {
            order_id: e
        }, function(t) {
            0 === t.errno && a.setData({
                eva: t.data
            });
        });
    },
    submitEva: function() {
        0 == this.data.score ? wx.showToast({
            title: "请点击小星星",
            icon: "none"
        }) : this.data.order.ws_id ? (wx.showLoading({
            title: "提交中",
            mask: !0
        }), t.com.post("wx/evaluate/add", {
            score: this.data.score,
            order_id: this.data.order.id,
            msg: this.data.textarea,
            ws_id: this.data.order.ws_id
        }, function(t) {
            0 === t.errno && (wx.showToast({
                title: t.errmsg
            }), a.getEva(a.data.order.id));
        })) : wx.showToast({
            title: "该订单还没有被接单",
            icon: "none"
        });
    },
    onLoad: function(t) {
        (a = this).setData({
            order_no: t.order_no
        });
    },
    onShow: function() {
        a.getOrder(this.data.order_no);
    },
    getOrder: function(e) {
        wx.showLoading({
            title: "加载中"
        }), t.com.post("wx/order/find", {
            order_no: e
        }, function(t) {
            wx.hideLoading(), 0 === t.errno && ("nearby" != t.data.start_address && (t.data.start_address = JSON.parse(t.data.start_address)), 
            t.data.end_address.id || (t.data.end_address = JSON.parse(t.data.end_address)), 
            t.data.filterDistance = (t.data.distance / 1e3).toFixed(2), a.setData({
                order: t.data
            }), 0 != t.data.ws_id && a.getService(t.data.ws_id), a.getEva(t.data.id));
        });
    },
    makePhoneCall: function() {
        wx.makePhoneCall({
            phoneNumber: this.data.phone
        });
    },
    cancelOrder: function() {
        wx.navigateTo({
            url: "/pages/order/cancel/cancel?order_id=" + this.data.order.id + "&order_no=" + this.data.order.order_no + "&type=1"
        });
    },
    getService: function(e) {
        t.com.post("wx/service/orderfind", {
            ws_id: e
        }, function(t) {
            0 === t.errno && a.setData(t.data);
        });
    }
});